```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>StringBuffer类详解 | Java字符串处理指南</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.8;
            color: #333;
            background-color: #f9fafb;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .code-block {
            background-color: #2d3748;
            border-radius: 0.5rem;
            overflow: hidden;
        }
        .code-header {
            background-color: #1a202c;
            padding: 0.5rem 1rem;
            display: flex;
            align-items: center;
        }
        .code-dots {
            display: flex;
            gap: 0.5rem;
        }
        .code-dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        .dot-red {
            background-color: #f56565;
        }
        .dot-yellow {
            background-color: #ecc94b;
        }
        .dot-green {
            background-color: #48bb78;
        }
        .card-hover {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .feature-icon {
            width: 48px;
            height: 48px;
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 1rem;
        }
        .mermaid-tooltip {
            position: absolute;
            background: white;
            padding: 8px 12px;
            border-radius: 4px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.15);
            z-index: 100;
            font-size: 14px;
            pointer-events: none;
            opacity: 0;
            transition: opacity 0.2s;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:py-32">
        <div class="container mx-auto max-w-5xl text-center">
            <div class="inline-block px-3 py-1 mb-4 text-sm font-medium text-indigo-100 bg-indigo-800 bg-opacity-40 rounded-full backdrop-filter backdrop-blur-sm">
                <i class="fas fa-code mr-2"></i>Java核心类库
            </div>
            <h1 class="text-4xl md:text-6xl font-bold mb-6 leading-tight">StringBuffer类详解</h1>
            <p class="text-xl md:text-2xl text-indigo-100 max-w-3xl mx-auto mb-10">
                掌握Java中处理可变字符串的强大工具，提升字符串操作效率
            </p>
            <div class="flex flex-wrap justify-center gap-4">
                <a href="#overview" class="px-6 py-3 bg-white text-indigo-600 font-medium rounded-lg hover:bg-opacity-90 transition-all transform hover:scale-105 shadow-lg">
                    <i class="fas fa-book-open mr-2"></i>开始学习
                </a>
                <a href="#examples" class="px-6 py-3 border-2 border-white text-white font-medium rounded-lg hover:bg-white hover:bg-opacity-10 transition-all transform hover:scale-105">
                    <i class="fas fa-laptop-code mr-2"></i>查看示例
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto max-w-5xl px-4 py-12">
        <!-- Overview Section -->
        <section id="overview" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="h-1 w-12 bg-indigo-500 rounded-full mr-4"></div>
                <h2 class="text-3xl font-bold">StringBuffer类概述</h2>
            </div>
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <p class="text-lg text-gray-700 mb-6">
                        <span class="text-indigo-600 font-medium">StringBuffer</span> 是 <span class="font-medium">java.lang</span> 包中的一个类，用于表示可变的字符序列。与 <span class="font-medium">String</span> 类不同，<span class="text-indigo-600 font-medium">StringBuffer</span> 的对象可以修改其内容，包括插入、追加、删除等操作，而不会创建新的对象。
                    </p>
                    <div class="bg-blue-50 border-l-4 border-blue-500 p-4 mb-6 rounded-r">
                        <div class="flex">
                            <div class="flex-shrink-0">
                                <i class="fas fa-info-circle text-blue-500 text-xl"></i>
                            </div>
                            <div class="ml-3">
                                <p class="text-sm text-blue-700">
                                    关键区别：String对象是不可变的，每次修改都会创建新对象；而StringBuffer对象是可变的，修改操作直接在原对象上进行。
                                </p>
                            </div>
                        </div>
                    </div>
                    <p class="text-gray-700">
                        在需要频繁修改字符串内容的场景下，使用StringBuffer可以显著提升性能，避免不必要的对象创建和内存分配。
                    </p>
                </div>
                <div class="code-block">
                    <div class="code-header">
                        <div class="code-dots">
                            <div class="code-dot dot-red"></div>
                            <div class="code-dot dot-yellow"></div>
                            <div class="code-dot dot-green"></div>
                        </div>
                        <div class="ml-2 text-gray-300 text-sm">StringBuffer vs String</div>
                    </div>
                    <pre class="p-4 text-gray-100 overflow-x-auto"><code>// String - 不可变
String str = "Hello";
str += " World"; // 创建新对象

// StringBuffer - 可变
StringBuffer sb = new StringBuffer("Hello");
sb.append(" World"); // 修改原对象</code></pre>
                </div>
            </div>
        </section>

        <!-- Features Section -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="h-1 w-12 bg-indigo-500 rounded-full mr-4"></div>
                <h2 class="text-3xl font-bold">StringBuffer类的特点</h2>
            </div>
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                    <div class="feature-icon bg-indigo-100 text-indigo-600">
                        <i class="fas fa-sync-alt text-xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">可变性</h3>
                    <p class="text-gray-600">
                        StringBuffer类的对象是可变的，可以通过一系列方法修改其内容，而不会创建新的对象。这使得它在需要频繁修改字符串的场景中非常高效。
                    </p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                    <div class="feature-icon bg-green-100 text-green-600">
                        <i class="fas fa-lock text-xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">线程安全</h3>
                    <p class="text-gray-600">
                        StringBuffer类是线程安全的，适用于多线程环境下的字符串操作。如果在单线程环境下使用，推荐使用性能更好的StringBuilder类。
                    </p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                    <div class="feature-icon bg-purple-100 text-purple-600">
                        <i class="fas fa-expand-alt text-xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">容量自动调整</h3>
                    <p class="text-gray-600">
                        StringBuffer类会自动调整其内部的字符数组容量，以适应字符串的长度变化。当字符串长度超过当前容量时，会自动扩容。
                    </p>
                </div>
            </div>
        </section>

        <!-- Visualization Section -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="h-1 w-12 bg-indigo-500 rounded-full mr-4"></div>
                <h2 class="text-3xl font-bold">StringBuffer内部机制</h2>
            </div>
            <div class="bg-white p-6 rounded-xl shadow-md">
                <div class="mermaid">
                    graph TD
                        A[StringBuffer对象] --> B[字符数组]
                        A --> C[长度count]
                        A --> D[容量capacity]
                        B --> E[动态扩容机制]
                        C --> F[实际字符数]
                        D --> G[当前数组大小]
                        E --> H[新容量 = (旧容量*2) + 2]
                        style A fill:#4f46e5,stroke:#333,color:#fff
                        style B fill:#7c3aed,stroke:#333,color:#fff
                        style C fill:#8b5cf6,stroke:#333,color:#fff
                        style D fill:#a78bfa,stroke:#333,color:#fff
                </div>
            </div>
        </section>

        <!-- Methods Section -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <div class="h-1 w-12 bg-indigo-500 rounded-full mr-4"></div>
                <h2 class="text-3xl font-bold">StringBuffer类的常用操作方法</h2>
            </div>
            <div class="overflow-x-auto">
                <table class="min-w-full divide-y divide-gray-200">
                    <thead class="bg-gray-50">
                        <tr>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">方法</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">描述</th>
                            <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">返回值</th>
                        </tr>
                    </thead>
                    <tbody class="bg-white divide-y divide-gray-200">
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-indigo-600">append()</td>
                            <td class="px-6 py-4 text-sm text-gray-500">将指定内容追加到字符串的末尾</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">StringBuffer</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-indigo-600">insert()</td>
                            <td class="px-6 py-4 text-sm text-gray-500">在指定位置插入指定内容</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">StringBuffer</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-indigo-600">delete()</td>
                            <td class="px-6 py-4 text-sm text-gray-500">删除指定范围内的字符</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">StringBuffer</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-indigo-600">reverse()</td>
                            <td class="px-6 py-4 text-sm text-gray-500">颠倒字符串中字符的顺序</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">StringBuffer</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-indigo-600">charAt()</td>
                            <td class="px-6 py-4 text-sm text-gray-500">获取指定索引位置的字符</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">char</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-indigo-600">setCharAt()</td>
                            <td class="px-6 py-4 text-sm text-gray-500">设置指定索引位置的字符</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">void</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-indigo-600">length()</td>
                            <td class="px-6 py-4 text-sm text-gray-500">获取当前字符串的长度</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">int</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-indigo-600">capacity()</td>
                            <td class="px-6 py-4 text-sm text-gray-500">获取当前容量</td>
                            <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">int</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </section>

        <!-- Examples Section -->
        <section id="examples" class="mb-16">
            <div class="flex items-center mb-8">
                <div class="h-1 w-12 bg-indigo-500 rounded-full mr-4"></div>
                <h2 class="text-3xl font-bold">使用示例</h2>
            </div>
            <div class="code-block mb-6">
                <div class="code-header">
                    <div class="code-dots">
                        <div class="code-dot dot-red"></div>
                        <div class="code-dot dot-yellow"></div>
                        <div class="code-dot dot-green"></div>
                    </div>
                    <div class="ml-2 text-gray-300 text-sm">StringBufferDemo.java</div>
                </div>
                <pre class="p-4 text-gray-100 overflow-x-auto"><code>public class StringBufferDemo {
    public static void main(String[] args) {
        // 创建一个 StringBuffer 对象
        StringBuffer stringBuffer = new StringBuffer("Hello");

        // 追加字符串
        stringBuffer.append(" World");
        System.out.println("追加字符串后：" + stringBuffer);

        // 在指定位置插入字符串
        stringBuffer.insert(5, ", ");
        System.out.println("插入字符串后：" + stringBuffer);

        // 删除指定范围内的字符
        stringBuffer.delete(5, 7);
        System.out.println("删除字符串后：" + stringBuffer);

        // 颠倒字符串中字符的顺序
        stringBuffer.reverse();
        System.out.println("颠倒字符串后：" + stringBuffer);
    }
}</code></pre>
            </div>
            <div class="bg-white p-6 rounded-xl shadow-md">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">输出结果</h3>
                <div class="bg-gray-800 text-green-400 p-4 rounded-lg">
                    <div class="mb-2">追加字符串后：Hello World</div>
                    <div class="mb-2">插入字符串后：Hello,  World</div>
                    <div class="mb-2">删除字符串后：Hello World</div>
                    <div>颠倒字符串后：dlroW olleH</div>
                </div>
            </div>
        </section>

        <!-- Tips Section -->
        <section>
            <div class="flex items-center mb-8">
                <div class="h-1 w-12 bg-indigo-500 rounded-full mr-4"></div>
                <h2 class="text-3xl font-bold">注意事项</h2>
            </div>
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                    <h3 class="text-xl font-semibold mb-3 flex items-center">
                        <i class="fas fa-tachometer-alt text-indigo-500 mr-2"></i>
                        性能考虑
                    </h3>
                    <p class="text-gray-600">
                        在单线程环境下，如果不需要线程安全性，推荐使用性能更好的 <span class="font-medium text-indigo-600">StringBuilder</span> 类。StringBuilder的API与StringBuffer几乎相同，但没有同步开销。
                    </p>
                </div>
                <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                    <h3 class="text-xl font-semibold mb-3 flex items-center">
                        <i class="fas fa-chart-line text-indigo-500 mr-2"></i>
                        容量预估
                    </h3>
                    <p class="text-gray-600">
                        如果事先知道字符串的大致长度，可以使用StringBuffer的构造方法或 <span class="font-medium text-indigo-600">ensureCapacity()</span> 方法来提前预估容量，避免频繁扩容带来的性能开销。
                    </p>
                </div>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-semibold text-white mb-1">技术小馆</h3>
                    <p class="text-gray-400">专业的编程技术学习平台</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" target="_blank" class="text-indigo-300 hover:text-white transition-colors duration-200">
                        <i class="fas fa-globe mr-2"></i>www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-sm text-gray-500">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'dark',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });

        // Add hover effect for mermaid diagram
        document.addEventListener('DOMContentLoaded', function() {
            const mermaidElements = document.querySelectorAll('.mermaid');
            const tooltip = document.createElement('div');
            tooltip.className = 'mermaid-tooltip';
            document.body.appendChild(tooltip);

            mermaidElements.forEach(element => {
                element.addEventListener('mousemove', function(e) {
                    const target = e.target;
                    if (target.tagName === 'text' && target.textContent) {
                        tooltip.textContent = target.textContent;
                        tooltip.style.left = (e.pageX + 10) + 'px';
                        tooltip.style.top = (e.pageY + 10) + 'px';
                        tooltip.style.opacity = '1';
                    } else {
                        tooltip.style.opacity = '0';
                    }
                });

                element.addEventListener('mouseleave', function() {
                    tooltip.style.opacity = '0';
                });
            });
        });
    </script>
</body>
</html>
```